{% extends "base.html" %}
{% block page_title %}Realtime Prefix Hijacking Alarms{% endblock %}
{% block content %}
  <div id="featured-projects">
    <h4>Latest Hijacking Alarm</h4>
    <table>
      <tr>
        <th>Time (UTC)</th>
        <!--<th>Timestamp</th>-->
        <th>IP Prefix</th>
        <th>CC</th>
        <th>Anomalous AS Path Segment</th>
        <th>Alarm Delay(s)</th>
        <th>Alarm Lasts(s)</th>
        <th>Avg Fing. [0.6, 1]</th>
      </tr>
      {% for alarm in alarms %}
      <tr>
        <td>{{ alarm.1 }}</td>
        <!--<td>{{ alarm.0.time }}</td>-->
        <td>
          <a href="http://bgp.he.net/net/{{ alarm.0.prefix_dec }}" target="_blank">{{ alarm.0.prefix_dec }}</a>
          {% if alarm.8 %}<a href="/fingerprints/{{ alarm.0.alarm_id }}#prefixes" target="_blank"><b>+{{ alarm.8|length }}</b></a>
          {% endif %} 
        </td>
        <td>{{ alarm.9 }}</td>
        <td align=right>
          {% if alarm.0.homeas %}
          O: {% if alarm.0.oldhomeas %}<a href="http://bgp.he.net/AS{{ alarm.0.oldhomeas }}#_prefixes" target="_blank">AS{{ alarm.0.oldhomeas }}</a>{% else %}N/A{% endif %}
          -&gt; <a href="http://bgp.he.net/AS{{ alarm.0.homeas }}#_prefixes" target="_blank">AS{{ alarm.0.homeas }}</a>
          {% else %}
            {% if alarm.5 %}P:
          <a href="http://bgp.he.net/AS{{ alarm.5 }}#_graph4" target="_blank">AS{{ alarm.5 }}</a>
            {% else %}N:
            {% endif %}
          <a href="http://bgp.he.net/AS{{ alarm.6 }}#_graph4" target="_blank">AS{{ alarm.6 }}</a>
          <a href="http://bgp.he.net/AS{{ alarm.7 }}#_graph4" target="_blank">AS{{ alarm.7 }}</a>
          {% endif %}
        </td>
        <td align=right>{{ alarm.2 }}</td>
        <td align=right>{{ alarm.3 }}</td>
        <td align=right>{{ alarm.4 }}</td>
      </tr>
      {% endfor %}
      <tr><td colspan=7><br/></td></tr>
      <tr>
        <td align=center colspan=7>
          <div id="container" style="width: 100%"></div>
        </td>
      </tr>
    </table>
  </div><!--end featured-projects-->
  <!--
  <div id="featured-projects">
    <h4>Recent Routing Anomaly</h4>
    <table>
      <tr>
        <th>Time (UTC)</th>
        <th>IP Prefix</th>
        <th>CC</th>
        <th>Anomalous AS Path Segment</th>
        <th>Max Fing.</th>
        <th>Min Fing.</th>
        <th>Avg Fing. [-1, 1]</th>
        <th>Plot</th>
      </tr>
      {% for anomaly in anomalies %}
      <tr>
        <td>{{ anomaly.1 }}</td>
        <td>
          <a href="http://bgp.he.net/net/{{ anomaly.0.prefix_dec }}" target="_blank">{{ anomaly.0.prefix_dec }}</a>
          {% if anomaly.8 %}<a href="/fingerprints/{{ anomaly.0.alarm_id }}#prefixes" target="_blank"><b>+{{ anomaly.8 }}</b></a>
          {% endif %}
        </td>
        <td>{{ anomaly.9 }}</td>
        <td align=right>
          {% if anomaly.0.homeas %}
          O: {% if anomaly.0.oldhomeas %}<a href="http://bgp.he.net/AS{{ anomaly.0.oldhomeas }}#_prefixes" target="_blank">AS{{ anomaly.0.oldhomeas }}</a>{% else %}N/A{% endif %}
          -&gt; <a href="http://bgp.he.net/AS{{ anomaly.0.homeas }}#_prefixes" target="_blank">AS{{ anomaly.0.homeas }}</a>
          {% else %}
            {% if anomaly.5 %}P:
          <a href="http://bgp.he.net/AS{{ anomaly.5 }}#_graph4" target="_blank">AS{{ anomaly.5 }}</a>
            {% else %}N:
            {% endif %}
          <a href="http://bgp.he.net/AS{{ anomaly.6 }}#_graph4" target="_blank">AS{{ anomaly.6 }}</a>
          <a href="http://bgp.he.net/AS{{ anomaly.7 }}#_graph4" target="_blank">AS{{ anomaly.7 }}</a>
          {% endif %}
        </td>
        <td align=right>{{ anomaly.2 }}</td>
        <td align=right>{{ anomaly.3 }}</td>
        <td align=right>{{ anomaly.4 }}</td>
        <td><a href="/fingerprints/{{ anomaly.0.alarm_id }}" target="_blank">plot</a></td>
      </tr>
      {% endfor %}
    </table>
    Now: {{ currtime }}
  </div><#!- -end featured-projects-->
{% endblock %}
{% block js_script %}
  <script src="/static/jquery-latest.js"></script>
  <!--<script src="/static/jquery.custom.js"></script>-->
  <script type="text/javascript" src="/static/highcharts/highcharts.js"></script>
  <script type="text/javascript">
    var chart;
    $(document).ready(function() {
      chart = new Highcharts.Chart({
        chart: { renderTo: 'container', zoomType: 'x' },
        title: { text: 'Fingerprints and # anomalous routers along with time' },
        xAxis: {
          min: 0,
          max: 120,
          title: { text: 'Seconds after the first anomalous BGP update' },
          type: 'linear'
        },
        yAxis: [{ // Fingerprints
          title: {
            text: 'Fingerprint',
            style: { color: '#4572A7' }
          },
          min: -1.0,
          max: 1.0,
          minorGridLineWidth: 0,
          gridLineWidth: 1,
          alternateGridColor: null,
          plotBands: [{ // Hijacking
            from: 0.6,
            to: 1.0,
            color: 'rgba(68, 170, 213, 0.1)',
            label: {
              text: 'Prefix Hijacking',
              style: { color: '#606060' }
            }
          }, { // Route Change
            from: -0.6,
            to: 0.6,
            color: 'rgba(0, 0, 0, 0)',
            label: {
              text: 'Route Change',
              style: { color: '#606060' }
            }
          }, { // Service Change
            from: -1.0,
            to: -0.6,
            color: 'rgba(68, 170, 213, 0.1)',
            label: {
              text: 'Service Change',
              style: { color: '#606060' }
            }
          }]
        }, { // # Anomalous Routers
          title: {
            text: '# Anomalous Routers',
            style: { color: '#AA4643' }
          },
          min: 0,
          max: 40,
          opposite: true
        }],
        tooltip: {
          shared: true,
          crosshairs: true,
          headerFormat: '<small>{point.key}-th second</small><br/>'
        },
        plotOptions: {
          column: {
            minPointLength: 1,
            pointPadding: 0,
            groupPadding: 0,
            borderWidth: 0.1,
            shadow: false
          },
          spline: { marker: { enabled: false, } }
        },
        series: [{
          name: 'Fingerprint',
          type: 'column',
          yAxis: 0,
          data: [
           {% for sg in sigs %}
           [{{ forloop.counter0 }} + {{ base }}, {{ sg }}],
           {% endfor %}
          ] 
        }, {
          name: '# Anomalous Routers',
          type: 'spline',
          yAxis: 1,
          data: [
           {% for ct in cnt0 %}
           [{{ forloop.counter0 }} + {{ base }}, {{ ct }}],
           {% endfor %}
          ] 
        }]
      });
    });
  </script>
{% endblock %}
